
<%@page contentType="text/html" pageEncoding="windows-1252"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="startup.model.trip.MissionRequest"%>
<%@page import="startup.model.trip.Reimbursement"%>
<%@page import="startup.model.user.Student"%>
<%@page import="startup.utils.Query"%>
<%
	try
	{
		Student student = ( Student )session.getAttribute( "currentSessionUser" );
		student.completeAttributesFromWorkingDB();

		int missionId = Integer.parseInt( request.getParameter( "tripId" ) );
		MissionRequest advanceReimbursement = ( ( Student )session.getAttribute( "currentSessionUser" ) ).getHistory().getMissionById( missionId );
		session.setAttribute( "missionRequest", advanceReimbursement );
		String studentId = ( ( Student )session.getAttribute( "currentSessionUser" ) ).getId().toString();
		String studentsPersonalFunds = ( ( Student )session.getAttribute( "currentSessionUser" ) ).getPersonalFunds().toString();
%>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="windows-1252">
        <title>New Reimbursement</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="author" content="">
        <!-- Le styles -->
        <link href="styles/bootstrap.css" rel="stylesheet">
        <style type="text/css">
            body 
            {
                padding-top: 60px;
                padding-bottom: 40px;
            }
            .sidebar-nav
            {
                padding: 9px 0;
            }
        </style>
    </head>
    <body>
        <!--Barra Superiore-->
        <div class="navbar navbar-fixed-top">
            <div class="navbar-inner">
                <div class="container-fluid">
                    <a class="brand" href="#">Student : <%=student.getSurname()%> <%=student.getName()%></a>
                    <div class="nav pull-right">
                        <ul class="nav">
                            <li>
                                <form action="Logout" method="post">
                                    <button class="btn btn-primary btn-small">Sign out</button>
                                </form>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>
        <div class="container-fluid">
            <div class="row-fluid">
                <div class="span3" style="position:fixed;">
                    <div class="well sidebar-nav">
                        <ul class="nav nav-list">
                            <li class="nav-header">Location</li>
                            <li><a href="studentChooseHistoryToShow.jsp"><i class="icon-home"></i> Home</a></li>
                            <li><a href="studentActualHistory.jsp"> &nbsp; &bull; <i class="icon-th-large"></i> ACTIVE History</a></li>                            
                            <li><a href="studentTerminatedHistory.jsp"> &nbsp; &bull; <i class="icon-th-large"></i> TERMINATED History</a></li>
                            <li><a href="studentDeletedHistory.jsp"> &nbsp; &bull; <i class="icon-th-large"></i> DELETED History</a></li>
                            <li class="nav-header">Function</li>
                            <li><a href="studentNewMissionRequestSubmission.jsp"><i class="icon-pencil"></i> New Mission Request</a></li>
                            <li><a href="studentShowNewAdvanceCompensation.jsp"><i class="icon-pencil"></i> New Advance Compensation</a></li>
                            <li><a href="studentShowNewReimbursement.jsp"><i class="icon-pencil"></i> New Reimbursement</a></li>
                            <li class="active"><a href="#"> &nbsp; &bull; <i class="icon-white icon-tasks"></i> Complete the forms </a></li>
                            <li class="divider"></li>
                            <li><a href="studentFAQ.jsp"><i class="icon-info-sign"></i> F.A.Q.</a></li>             
                        </ul>
                    </div><!--/.well -->
                </div><!--/span-->
                <div class="span9" style="margin-left: 26%;">
                    <form action="studentSubmitReimbursement.jsp" method="post">
                        <div class="row-fluid">
                            <div class="hero-unit">
                                <h1>New Reimbursement</h1>                        
                            </div>
                            <div class="row-fluid">
                                <div class="row-fluid">
                                    <div class="span5">
                                        <% if( advanceReimbursement.getAdvanceCompensation() != null )
											{
												Integer advanceCompensationRecived = advanceReimbursement.getAdvanceCompensation().getFirstAlternativeFundAmount() +
																					 advanceReimbursement.getAdvanceCompensation().getSecondAlternativeFundAmount() +
																					 advanceReimbursement.getAdvanceCompensation().getPersonalFundsAmount();
                                        %>
                                        <p>
                                            Advance compensation received: <%=advanceCompensationRecived.toString()%>
                                        </p>
                                        <%
											}
											if( advanceReimbursement.getAdvanceCompensation() != null )
											{
                                        %>
                                        <p>
                                        <h4>Expenses sustained before trip: <%=advanceReimbursement.getAdvanceCompensation().getTotalExpenses()%></h4>
                                        <input type="hidden" name="expenses" value="<%=advanceReimbursement.getAdvanceCompensation().getTotalExpenses()%>" />
                                        <%
										}
										else
										{
                                        %>
                                        <h4>Expenses sustained before trip: 0</h4>
                                        <input type="hidden" name="expenses" value="0" />
                                        <%											}
                                        %>
                                        <br />
                                        <br />
                                        <br />
                                        <h4>Reimbursement of travel expenses to: *</h4>
                                        <textarea maxlength="255" name="actual_destination" ><%=advanceReimbursement.getDestination()%></textarea>
                                        <br />
                                        <br />
                                        <br />
                                        <h4>Begin date and time: *</h4>
                                        <input type="datetime" name="actual_begin_date_time" value="<%=advanceReimbursement.getPlannedStartDate().toString()%>"/>
                                        <br />
                                        <br />
                                        <br />
                                        <h4>End date and time: *</h4>
                                        <input type="datetime" name="actual_end_date_time" value="<%=advanceReimbursement.getPlannedEndDate().toString()%>" />
                                        <br />
                                        <br />
                                        <br />
                                        <h4>Accomodation expenses in attachment no.: *</h4>
                                        <input type="number" maxlength="9" name="num_lodging_receipts" value="0" />
                                        <br />
                                        <br />
                                        <br />
                                        <h4>Fiscal receipts/invoices for no. of days: *</h4>
                                        <input type="number" maxlength="9" name="number_of_nights" value="0" />
                                        <br />
                                        <br />
                                        <br />
                                        <h4>Registration fees to a conference/congress authorized and paid directly: *</h4>
                                        <input type="number" maxlength="9" name="registration_fee" value="0" />
                                        <br />
                                        <br />
                                        <br />
                                        <h4>Total lodging expenses: *</h4>
                                        <input type="number" maxlength="9" name="total_lodging_expenses" value="0" />
                                        <br />
                                        <br />
                                        <br />
                                        <h4>Meals in attachment no.: *</h4>
                                        <input type="number" maxlength="9" name="num_meals_invoices" value="0" />
                                        <br />
                                        <br />
                                        <br />
                                        <h4>Number of days of Meals: *</h4>
                                        <input type="number" maxlength="9" name="num_days_of_meals" value="0" />
                                        <br />
                                        <br />
                                        <br />
                                        <h4>Total meal expenses: *</h4>
                                        <input type="number" maxlength="9" name="total_meal_expenses" value="0" />
                                        <br />
                                        <br />
                                        <br />
                                    </div>
                                    <div class="span5">
										<br />
                                        <h3>Travel tickets:</h3>  
                                        <br />
                                        <h4> Departure: *</h4>
                                        <%											{
												String fromDeparture = "";
												String toDeparture = "";
												String fromReturn = "";
												String toReturn = "";

												boolean hasAdvance = false;
												if( advanceReimbursement.getAdvanceCompensation() != null )
												{
													hasAdvance = true;
												}
												if( hasAdvance )
												{
													fromDeparture = advanceReimbursement.getAdvanceCompensation().getDepartureFrom();
													toDeparture = advanceReimbursement.getAdvanceCompensation().getDepartureTo();
													fromReturn = advanceReimbursement.getAdvanceCompensation().getReturnFrom();
													toReturn = advanceReimbursement.getAdvanceCompensation().getReturnTo();
												}
                                        %>
                                        <h5> From: *</h5>
                                        <input name="fromDeparture" type="text" value="<%=fromDeparture%>" />
                                        <h5> To: *</h5>
                                        <input name="toDeparture" type="text" value="<%=toDeparture%>" />
                                        <h5> Date: *</h5>
                                        <%
											if( hasAdvance )
											{
                                        %>
                                        <input name="dateDeparture" type="date" value="<%=advanceReimbursement.getAdvanceCompensation().getDepartureDate()%>" />
                                        <%
										}
										else
										{
                                        %>
                                        <input name="dateDeparture" type="date" value="yyyy-mm-dd" />
                                        <%											}
                                        %>
                                        <h4> Return: </h4>
                                        <h5> From: *</h5>
                                        <input name="fromReturn" type="text" value="<%=fromReturn%>" />
                                        <h5> To: *</h5>
                                        <input name="toReturn" type="text" value="<%=toReturn%>" />
                                        <h5> Date: *</h5>
                                        <%
											if( hasAdvance )
											{
                                        %>
                                        <input name="dateReturn" type="date" value="<%=advanceReimbursement.getAdvanceCompensation().getReturnDate()%>" />
                                        <%
										}
										else
										{
                                        %>
                                        <input name="dateReturn" type="date" value="yyyy-mm-dd" />
                                        <%											}
											}
                                        %>
                                        <p>
                                        <h4>Departure border cross datetime: *</h4>
                                        <input type="datetime" name="departure_border_cross_datetime" value="yyyy-MM-ddThh:mm:ssZ"/>
                                        <br />
                                        <br />
                                        <br />
                                        <h4>Arrival border cross datetime: *</h4>
                                        <input type="datetime" name="arrival_border_cross_datetime" value="yyyy-MM-ddThh:mm:ssZ"/>
                                        <br />
                                        <br />
                                        <br />
                                        <h4>Highway toll fees: *</h4>
                                        <input type="number" maxlength="9" name="highway_toll_fees" value="0" />
                                        <br />
                                        <br />
                                        <br />
                                        <h4>Personal vehicle KM travelled: *</h4>
                                        <input type="number" maxlength="9" name="personal_veichle_KM_travelled" value="0" />
                                        <br />
                                        <br />
                                        <br />
                                        <h4>Personal colleagues</h4>
                                        <textarea maxlength="255" name="personal_veichle_colleagues" ></textarea>
                                        <br />
                                        <br />
                                        <br />
                                        <h4>Total transport expenses: *</h4>
                                        <input type="number" maxlength="9" name="total_transport_expenses" value="0" />
                                        <br />
                                        <br />
                                        <br />
                                        <h4>Self declaration missing recepits:</h4>
                                        <textarea name="self_declaration_missing_recepits" ></textarea>
                                        <br />
                                        <br />
                                        <br />
                                    </div>
                                </div>
                                <div class="row-fluid">
									<h4>Other costs description:</h4>
                                    <textarea maxlength="255" name="other_costs_description" ></textarea>
                                    <br />
									<br />
									<br />
                                    <h4>Other costs amount: *</h4>
                                    <input type="number" maxlength="9" name="other_costs_amount" value="0" />
                                    <br />
									<br />
									<br />
                                    <h4>Requested payment method: *</h4>
                                    <br />
                                    <input name="paymentMethod" type="radio" value="CASH" /> Cash
                                    <br />
                                    <input name="paymentMethod" type="radio" value="BANK" /> Bank Account
                                    <br />
									<br />
									<br />
                                    <h3>Used Funds</h3>
                                    <%

										if( advanceReimbursement.getArePersonalFundsUsed().booleanValue() )
										{
                                    %>
                                    <p>
                                        Personal funds amount: <%=studentsPersonalFunds%> <br />
                                        How many personal funds do you want to use? 
                                        <br />
                                        <input id="personalFundsUsed" name="personalFundsUsed" type="number" maxlength="9" value="0" /><br />
                                    </p>
                                    <%																					}
										if( advanceReimbursement.getFirstAlternativeFundManagerId() != null && advanceReimbursement.getFirstAlternativeFundManagerId() > 0 )
										{
                                    %>
                                    <p>
                                        How many funds of <%= advanceReimbursement.getFirstAlternativeFundName()%> do you want to use? 
                                        <br />
                                        <input id="firstFundAmount" name="firstFundAmount" type="number" maxlength="9" value="0" /><br />
                                    </p>
                                    <%}
										if( advanceReimbursement.getSecondAlternativeFundManagerId() != null && advanceReimbursement.getSecondAlternativeFundManagerId() > 0 )
										{
                                    %>
                                    <p>
                                        How many funds of <%= advanceReimbursement.getSecondAlternativeFundName()%> do you want to use? 
                                        <br />
                                        <input id="secondFundAmount" name="secondFundAmount" type="number" maxlength="9" value="0" /><br />
                                    </p>
                                    <%
										}
                                    %>
									<p>
										Please note that if you spend more money than your available funds or funds that you indicated, you will not be reimbursed the difference.
									</p>
                                </div>
                            </div>
                        </div>
                        <hr />
                        <div class="row-fluid">
                            <table>
                                <tr>                                                    
                                    <td>
                                        <a class="btn btn-primary" data-toggle="modal" href="#Submit" >Submit</a>    
                                        <!--MODAL che appare quando si clicca su Refuse-->
                                        <div class="modal hide fade" id="Submit">
                                            <div class="modal-header">
                                                <button class="close" data-dismiss="modal">x</button>
                                                <h3>Are You Sure?</h3>
                                            </div>
                                            <div class="modal-body">
                                                <p>Click "Save Changes" to SUBMIT the trip, Close instead.</p>
                                            </div>
                                            <div class="modal-footer">    
                                                <table>
                                                    <tr>                                                    
                                                        <td>
                                                            <button class="btn btn-primary btn-success" onclick="">Save Changes</button>
                                                        </td>
                                                        <td>
                                                            <button class="btn" data-dismiss="modal">Close</button>
                                                        </td>
                                                    </tr>
                                                </table>  
                                            </div>
                                        </div>
                                    </td>
                                    <td>
                                        <button class="btn btn-primary" type="reset" >Reset</button>
                                    </td>
                                </tr>
                            </table>
                        </div>	
                    </form>
                </div>
            </div>
        </div><!--/.fluid-container-->
        <div class="navbarCC navbar-fixed-bottom">
            <div class="navbarCC-inner">
                <div class="container-fluid">				
                    <a class="brand" href="#">&copy; 2012 Startup</a>					
                </div>
            </div>
        </div>
		<!-- Il javascript -->
		<script src="js/jquery.js"></script>
		<script src="js/bootstrap.js"></script>
	</body>
</html>
<%
	}
	catch( RuntimeException runtimeException )
	{
		if( runtimeException.getClass().equals( NullPointerException.class ) )
		{
			runtimeException = new NullPointerException( "The session has timed out:<br />" + "" +
														 "try reloading page.<br />" +
														 "If the problem persists, please report it to the administration." );
		}
		request.setAttribute( "exception", runtimeException );
		request.getRequestDispatcher( "errorPage.jsp" ).forward( request, response );
	}
%>